import java.util.Arrays;

public class MyBitSet {
    public byte[] elem;
    public int usedSize;
    public MyBitSet() {
        this.elem = new byte[1];
    }
    public MyBitSet(int n) {
        this.elem = new byte[n/8+1];
    }
    public void set(int val) {
        if(val < 0) {
            throw new RuntimeException();
        }
        if(isFull()) {
            elem = Arrays.copyOf(elem, elem.length * 2);
        }
        int index = val / 8;
        int bitIndex = val % 8;
        elem[index] |= (1 << bitIndex);
        usedSize++;
    }
    public boolean get(int val) {
        if(val < 0) {
            throw new RuntimeException();
        }
        int index = val / 8;
        int bitIndex = val % 8;
        return (elem[index] & (1 << bitIndex)) != 0;
    }
    public void reSet(int val) {
        if(val < 0) {
            throw new RuntimeException();
        }
        int index = val / 8;
        int bitIndex = val % 8;
        elem[index] &= ~(1 << bitIndex);
        usedSize--;
    }
    public int getSize() {
        return usedSize;
    }

    public boolean isFull() {
        return elem.length * 8 == usedSize;
    }
}
